from odoo import api, fields, models
from odoo.exceptions import ValidationError

class QualityAlert(models.Model):
    _inherit = 'quality.alert'

    def action_confirm(self):
        # print(self._context.get('hand_workorder', None))
        if self.s_production_id and self.s_production_id.s_mes_lock and self._context.get('hand_workorder', None):
            raise ValidationError('当前工单已经推送MES，不允许在ERP报废')
        return super().action_confirm()

    def action_revocation(self):
        # print("self._context.get('hand_workorder', None)", self._context.get('hand_workorder', None))
        if self.s_production_id and self.s_production_id.s_mes_lock and self.s_mes_code and self._context.get('hand_workorder', None):
            raise ValidationError('当前报废由mes发起，不允许在ERP撤回')
        return super().action_revocation()
